home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <egb.h>
- #include "symbol.h"
- #include "vircon.h"
- #define ON 1
- #define OFF 0
- #define NOERR 0
- #define ERR 1
- #define BTC_OFF 0
- #define BTC_ON 2
-
- typedef struct
- {
- int used;
- int type;
- int bx,by,dx,dy;
- char *mes;
- int state;
- /* char *g_buf;*/
- } BUTTON ;
-
- static char *egbwork;
- static BUTTON b_dat[16];
-
- void BT_init( char *w );
- int BT_create( int type, int bx, int by, int dx, int dy, char *mes );
- int BT_getStatus( int num, int *state );
- int BT_reverse( int num, int in );
- int BT_disappear( int num );
- int BT_check( int num, int cx, int cy );
- static void _BT_putNormal( BUTTON b );
- static void _BT_putReverse( BUTTON b );
-
- void BT_init( char *w )
- {
- int i;
- for( i=0; i<16; i++ )
- b_dat[i].used = OFF;
- egbwork = w;
- return;
- }
-
- /*
- BT_create( int type, int bx, int by, int dx, int dy, char *mes );
- 引き数 type ボタンのタイプ(0:表示しない 1:表示する)
- (bx,by) ボタンの左上の座標
- dx x方向のドット数
- dy y方向のドット数
- mes ボタンに書く文字(NULLは無地のボタン)
- 返り値 0-15 ボタン番号
- -1 ボタンが既に16個作られている
- */
-
- int BT_create( int type, int bx, int by, int dx, int dy, char *mes )
- {
- int i;
-
- for( i=0; i<16; i++ )
- {
- if( b_dat[i].used == OFF )
- break;
- }
- if( i>15 )
- return -1;
-
- VC_printf( "BT %d ", L_INT, i );
- b_dat[i].used = ON;
- b_dat[i].type = type;
- b_dat[i].bx = bx;
- b_dat[i].by = by;
- b_dat[i].dx = dx;
- b_dat[i].dy = dy;
- b_dat[i].mes = mes;
- b_dat[i].state = OFF;
-
- _BT_putNormal( b_dat[i] );
- VC_printf( " %d\n", L_INT, i );
-
- return i;
- }
-
- int BT_getState( int num, int *state )
- {
- if( b_dat[num].used == OFF )
- return ERR;
- *state = b_dat[num].state;
- return NOERR;
- }
-
- int BT_reverse( int num, int in )
- {
- if( b_dat[num].used == OFF )
- return ERR;
- switch( in )
- {
- case 0:
- if( b_dat[num].state == ON )
- {
- _BT_putNormal( b_dat[num] );
- b_dat[num].state = OFF;
- }
- break;
- case 1:
- if( b_dat[num].state == OFF )
- {
- _BT_putReverse( b_dat[num] );
- b_dat[num].state = ON;
- }
- break;
- case 2:
- if( b_dat[num].state == ON )
- {
- _BT_putNormal( b_dat[num] );
- b_dat[num].state = OFF;
- }
- else
- {
- _BT_putReverse( b_dat[num] );
- b_dat[num].state = ON;
- }
- break;
- default:
- return ERR;
- }
- return NOERR;
- }
-
- int BT_disappear( int num )
- {
- if( b_dat[num].used == OFF )
- return ERR;
- b_dat[num].used = OFF;
- return NOERR;
- }
-
- int BT_check( int num, int cx, int cy )
- {
- if( b_dat[num].used == OFF )
- return ERR;
- if( cx<b_dat[num].bx || cx>b_dat[num].bx+b_dat[num].dx-1
- || cy<b_dat[num].by || cy>b_dat[num].by+b_dat[num].dy-1 )
- return BTC_OFF;
- return BTC_ON;
- }
-
- static void _BT_putNormal( BUTTON b )
- {
- if( b.type == 0 )
- return;
- EGB_writeMode( egbwork, 0 );
- EGB_paintMode( egbwork, 0x22 );
- EGB_paintColor( egbwork, 0 );
- EGB_foreColor( egbwork, 15 );
- EGB_box( egbwork, b.bx, b.by, b.bx+b.dx-1, b.by+b.dy-1 );
- symbol( egbwork, b.bx+b.dx/2-strlen(b.mes)*4, b.by+b.dy/2+7, b.mes );
- EGB_paintMode( egbwork, 0x02 );
- return;
- }
-
- static void _BT_putReverse( BUTTON b )
- {
- if( b.type == 0 )
- return;
- EGB_writeMode( egbwork, 0 );
- EGB_paintMode( egbwork, 0x22 );
- EGB_paintColor( egbwork, 15 );
- EGB_foreColor( egbwork, 15 );
- EGB_box( egbwork, b.bx, b.by, b.bx+b.dx-1, b.by+b.dy-1 );
- EGB_foreColor( egbwork, 8 );
- symbol( egbwork, b.bx+b.dx/2-strlen(b.mes)*4, b.by+b.dy/2+7, b.mes );
- EGB_paintMode( egbwork, 0x02 );
- return;
- }